from django.db import models


class UserInfo(models.Model):
    """
    用户模型
    """
    user_name = models.CharField(verbose_name='用户名', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=32)
    mobile = models.CharField(verbose_name='手机号', max_length=11)
    token = models.OneToOneField(verbose_name='token', to='UserToken', on_delete=models.SET_NULL, null=True, blank=True)
    depart = models.ForeignKey(verbose_name='部门', to='Depart', on_delete=models.SET_NULL, null=True, blank=True)

    def __str__(self):
        return self.user_name


class UserToken(models.Model):
    """
    用户令牌表
    """
    token = models.CharField(verbose_name='token', max_length=128, null=True, blank=True)

    def __str__(self):
        return self.token


class Depart(models.Model):
    """
    部门表
    """
    title = models.CharField(verbose_name='部门名称', max_length=32)
    permit_list = models.ManyToManyField(verbose_name='权限列表', to='Permit')

    def __str__(self):
        return self.title


class Permit(models.Model):
    """
    权限表
    """
    permit_choice = (
        (1, '增加'),
        (2, '修改'),
        (3, '删除'),
        (4, '详细'),
        (5, '列表')
    )
    permit = models.IntegerField(verbose_name='权限名', choices=permit_choice, default=5)

    def __str__(self):
        return self.get_permit_display()
